package android.framework.app;

import android.framework.R;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ProviderActivity extends Activity implements OnClickListener{
	/** Called when the activity is first created. */
	Uri uri;
	String AUTHORITY = "content://android.framework.provider/provider_tb";
	ContentResolver cr;
	EditText input;
	Button insert;
	TextView show;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_provider);
		input = (EditText) findViewById(R.id.input);
		insert = (Button) findViewById(R.id.insert);
		show = (TextView) findViewById(R.id.show);
		uri = Uri.parse(AUTHORITY);
		cr = this.getContentResolver();
		insert.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.insert:
			ContentValues values = new ContentValues();
			values.put("name", input.getText().toString());
			cr.insert(uri, values);
			Cursor c = cr.query(uri, null, null, null, null);
			show.setText("");
			c.moveToFirst();
			while (c.moveToNext()) {
				show.append(c.getString(1) + "\r\n");
			}
			input.setText("");
			break;
		default:
			break;
		}
		
	}
}